import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //通用服务器信息
    server: {
      serverName : '未选择服务器',
      serverId : '0',
    },
    //通用服务器列表
    serverList:null,
    //管理小标题是否显示
    titleState:true,
    //通用测评类型数组（指令、视频，全选）
    testType:[
      {
        value:'1',
        label:'华为指令流'
      },
      {
        value:'2',
        label:'华为视频流'
      },
      {
        value: '3',
        label: '所有'
      }
    ],
    functionList:{
      server : false,
      container :false,
      experience : false,
      system : false,
      user : false
    },
    exportDialog : false,
    token : localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : ''
  },
  mutations: {
    changeServerName(state,str){
      state.server.serverName=str
    },
    changeServerId(state,str){
      state.server.serverId=str
    },
    changeServerList(state,list){
      state.serverList=list
    },
    storeToken(state, user) {
      state.token = user.token;
      localStorage.setItem('Authorization', user.token);
    },
    changeFunction(state, func) {
      state.functionList[func] = true
    }
  },
  actions: {
  },
  modules: {
  },
  //通过Csion存储服务器选择
  plugins: [createPersistedState({
    storage:window.localStorage,
    reducer(val){
      return {
          server:val.server,
          serverList:val.serverList,
          functionList: val.functionList
      }
    }
  })]
})

// const store = new Vuex.Store({
//   state: {},
//   mutations: {},
//   actions: {},
//   plugins: [createPersistedState({
//     storage:window.sessionStorage,
//     reducer(val){
//       return {
//
//       }
//     }
//   })]
// })
